<?php

namespace App\Services\Admin\Users;

use App\Daos\Admin\Users\UsersDao;

class UsersService
{
    public static function userList ($search_part,$search_other,$search_tag,$search_visit,$search_order_num,$limit){
        foreach ($search_part as $key=>&$value){
            if (empty($search_part[$key])){
                unset($search_part[$key]);
            }
        }
        $data = UsersDao::userSelect($search_part,$search_other,$search_tag,$search_visit,$search_order_num,$limit);
        $data['count'] = (int)$data['count'][0]['count'];
        return $data;
    }

    public static function userAdd ($data){
        return UsersDao::userAdd($data);
    }

    public static function couponList ($offset,$search){
        $data = UsersDao::couponList($offset,$search);
        if (!$data){
            throw new \Exception('优惠券列表获取失败');
        }
        return $data;
    }

    public static function sendCoupon ($userid,$coupon){
        $userid = explode(',',substr($userid,0,-1));
        foreach ($userid as $value){
            $res = UsersDao::sendCoupon($value,$coupon);
        }
        return true;
    }

    public static function sendVip ($userid,$num){
        $res = UsersDao::sendVip($userid,$num);
        if (!$res){
            throw new \Exception('赠送会员失败');
        }
        return true;
    }
}
